package com.manager;


import java.util.ArrayList;
import java.util.List;

import com.sql.UserBDD;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class AddContactManagerActivity extends Activity implements OnClickListener {

	Button submitButton;
	EditText nameTxt;
	EditText surnameTxt;
	EditText pseudoTxt;
	EditText notesTxt;
	EditText addressTxt;
	EditText phoneTxt;
	EditText mailTxt;
	
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
        setContentView(R.layout.addcontacts);
        
        submitButton = (Button) findViewById(R.id.buttonSubmit);
        submitButton.setOnClickListener(this);
        
        nameTxt = (EditText) findViewById(R.id.editTextName);
        surnameTxt = (EditText) findViewById(R.id.editTextSurname);
        pseudoTxt = (EditText) findViewById(R.id.editTextPseudo);
        addressTxt = (EditText) findViewById(R.id.editTextAddress);
        phoneTxt = (EditText) findViewById(R.id.editTextPhone);
        mailTxt = (EditText) findViewById(R.id.editTextMail);
        
        
	}
	
	@Override
    public void onClick(View arg0)
    {
		switch(arg0.getId())
		{
		case R.id.buttonSubmit:
			insertContact();
			break;
		}
    }
	
	private void insertContact()
	{
		People obj = new People();
		List<String> phones = new ArrayList<String>();
		List<String> mails = new ArrayList<String>();
		UserBDD user = new UserBDD(this);
		Intent viewEntry= new Intent(AddContactManagerActivity.this, ContactActivity.class);
		
		phones.add(phoneTxt.getText().toString());
		mails.add(mailTxt.getText().toString());
		
		obj.set_name(nameTxt.getText().toString());
		obj.set_surname(surnameTxt.getText().toString());
		obj.set_pseudo(pseudoTxt.getText().toString());
		obj.setAddress(addressTxt.getText().toString());
		obj.set_phones(phones);
		obj.set_mails(mails);
		
		user.open();
		int res = user.insertUser(obj);
		
		People test = user.getUserbyID(res);
		Log.v("VALUE", test.get_name());
		Log.v("VALUE", String.valueOf(test.get_id()));	
		
		viewEntry.putExtra("id", res);				
		user.close();					
		startActivity(viewEntry);
		finish();
	}

}
